new Vue({
  el: '#app',
  data() {
    return {
      column:'',
      store:[],
      shop:[],
      form: {
        Sales_Unit_Price_SerialNumber: '',
        Start_Date: '',
        End_Date: '',
        ShopColumn_Id: '',
        Row_Status: '',
        Operation_ID: '',
        Operation_Datetime: '',
        Children: {
          sales_unitprice_detail: [{
            Sales_Unit_Price_Detail_SerialNumber: '',
            Sales_Unit_Price_SerialNumber: '',
            Article_SerialNumber: '',
            Unit_Price: '',
            Sales_Unit_Price: '',
            Row_Status: '',
            Operation_ID: '',
            Operation_Datetime: '',
          }],
          sales_unitprice_storescope: [{
            Sales_Unit_Price_StoreScope_SerialNumber: '',
            Sales_Unit_Price_SerialNumber: '',
            Store_SerialNumber: '',
            Row_Status: '',
            Operation_ID: '',
            Operation_Datetime: '',
          }]
        }
      },
    }
  },
  mounted() {
    const Sales_Unit_Price_SerialNumber = sessionStorage.getItem("Sales_Unit_Price_SerialNumber")
    this.getData(Sales_Unit_Price_SerialNumber)
  },
  methods: {
    getData(Sales_Unit_Price_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/SalesUnitprice_Edit',
        type: 'POST',
        data: { Data: Sales_Unit_Price_SerialNumber ,token:$.cookie("token")},
        async:false,
        success: function (res) {
          console.log(res);
          _this.form = res.sales_unitprice[0]
          if (!_this.form.Children.sales_unitprice_detail || _this.form.Children.sales_unitprice_detail.length == 0) {
            _this.form.Children.sales_unitprice_detail = [{
              Sales_Unit_Price_Detail_SerialNumber: '',
              Sales_Unit_Price_SerialNumber: this.form.Sales_Unit_Price_SerialNumber,
              Article_SerialNumber: '',
              Unit_Price: '',
              Sales_Unit_Price: '',
              Row_Status: '',
              Operation_ID: '',
              Operation_Datetime: '',
            }]
          }
          if (!_this.form.Children.sales_unitprice_storescope || _this.form.Children.sales_unitprice_storescope.length == 0) {
            _this.form.Children.sales_unitprice_storescope = [{
              Sales_Unit_Price_StoreScope_SerialNumber: '',
              Sales_Unit_Price_SerialNumber:this.form.Sales_Unit_Price_SerialNumber,
              Store_SerialNumber: '',
              Row_Status: '',
              Operation_ID: '',
              Operation_Datetime: '',
            }]
          }
        }
      })
      $.ajax({
        url: DomainName + '/StoreInfo',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          for (let i = 0; i < _this.form.Children.sales_unitprice_storescope.length; i++) {
            for (let j = 0; j < res.length; j++) {
              if (_this.form.Children.sales_unitprice_storescope[i].Store_SerialNumber == res[j].Store_SerialNumber) {
                _this.store.push(res[j].Store_Name);
              }
            }
          }
        }
      })
      $.ajax({
        url: DomainName + '/ShopColumn',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          res = res.filter(function (item) {
            return item.ShopColumn_Id == _this.form.ShopColumn_Id
          })
          _this.column = res[0].name;
        }
      })
      $.ajax({
        url: DomainName + '/ArticleInfo',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          for (let i = 0; i < _this.form.Children.sales_unitprice_detail.length; i++) {
            for (let j = 0; j < res.length; j++) {
              if (_this.form.Children.sales_unitprice_detail[i].Article_SerialNumber == res[j].Article_SerialNumber) {
                _this.shop.push(res[j].Article_Name);
              }
            }
          }
        }
      })
    }
  }
})